package cn.kgm.event;

import cn.hutool.json.JSONUtil;
import cn.kgm.event.request.EventReq;
import cn.kgm.event.service.UserService;
import cn.kgm.event.service.event.CreateUserEvent;
import cn.kgm.event.service.event.DeleteUserEvent;

public class HowToUseEvent {

    private static EventDispatcher eventDispatcher;

    public static void main(String[] args) {
        eventDispatcher = EventDispatcher.newBuilder()
                .onCreateUser(new UserService.CreateUserHandler() {
                    @Override
                    public void handle(CreateUserEvent event) throws Exception {
                        System.out.println("我来创建用户了" );
                    }
                })
                .onDeleteUser(new UserService.DeleteUserHandler() {
                    @Override
                    public void handle(DeleteUserEvent event) throws Exception {
                        System.out.println(JSONUtil.parse(event));
                    }
                }).build();
        eventDispatcher.handle(new EventReq());


        EventDispatcher.newBuilder()
                .build();
    }
}
